package vn.allmobile.newsreader.adapters;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import vn.allmobile.newsreader.R;
import vn.allmobile.newsreader.data.Category;
import vn.allmobile.newsreader.utils.ImageLoader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CategoryAdapter extends BaseAdapter {
	private ImageLoader mImageLoader;
	private Context mContext;
	private HashMap<String, Category> mCategories;
	private List mKeys;

	@SuppressWarnings("unchecked")
	public CategoryAdapter(Context context, HashMap<String, Category> categories) {
		this.mContext = context;
		this.mCategories = categories;
		this.mKeys = new ArrayList(this.mCategories.keySet());
	}

	@Override
	public int getCount() {
		return this.mCategories.size();
	}

	@Override
	public Object getItem(int arg0) {
		Object mKey = this.mKeys.get(arg0);
		return this.mCategories.get(mKey);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View mView = convertView;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) this.mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mView = inflater.inflate(
					R.layout.category_item, null);
		}
		Category mCategory = this.mCategories.get(this.mKeys.get(position));
		TextView mTitle = (TextView) mView.findViewById(R.id.grid_item_text);
		mTitle.setText(mCategory.getTitle());
		return mView;
		// return new View(parent.getContext());
	}
}
